<template>
  <div>
    <el-dialog
      title="修改教师信息"
      :visible.sync="dialogVisible"
      width="430px"
      :before-close="handleClose"
      :close-on-click-modal="false"
      center
    >
      <el-main>
        <div>
          <label>工号</label>
          <el-input v-model="teacherInfo.teacherId" size="small" />
        </div>
        <div>
          <label>姓名</label>
          <el-input v-model="teacherInfo.name" size="small" />
        </div>
        <div>
          <label>性别</label>
          <el-select v-model="teacherInfo.male" size="small">
            <el-option
              v-for="item in male"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>
        <div>
          <label>所属院系</label>
          <el-select v-model="teacherInfo.departmentId" size="small">
            <el-option
              v-for="item in departmentList"
              :key="item.departmentId"
              :label="item.departmentName"
              :value="item.departmentId"
            ></el-option>
          </el-select>
        </div>
        <div>
          <label>职称</label>
          <el-select v-model="teacherInfo.academicTitle" size="small">
            <el-option
              v-for="(item, index) in academicTitles"
              :key="index"
              :label="item"
              :value="item"
            ></el-option>
          </el-select>
        </div>
        <div>
          <label>联系方式</label>
          <el-input v-model="teacherInfo.phoneNumber" size="small"></el-input>
        </div>
      </el-main>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确认修改</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      teacherInfo: {
        teacherId: null,
        name: null,
        male: null,
        phoneNumber: null,
        departmentId: null,
        academicTitle: null,
      },
      departmentList: [],
      academicTitles: [],
      male: [
        {
          value: true,
          label: "男",
        },
        {
          value: false,
          label: "女",
        },
      ],
    };
  },
  methods: {
    // 返回职称
    returnacademicTitles() {
      this.$http.get(this.$api.InfoAcademicTitle).then((resp) => {
        if (resp.success) {
          this.academicTitles = resp.data.academicTitles;
        } else {
          this.$handleFailResp(this, resp);
        }
      });
    },
    //返回院系列表
    returnDepartment() {
      this.$http.get(this.$api.InfoDepartment).then((resp) => {
        if (resp.success) {
          this.departmentList = resp.data;
        } else {
          this.$handleFailResp(this, resp);
        }
      });
    },
    // 处理关闭
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    // 提交
    submit() {
      var _this = this;
      let options = this.teacherInfo;
      console.log(options);
      this.$http.post(this.$api.TeacherModifiedInfo, options).then((resp) => {
        if (resp.success) {
          _this.$myMessage.success(this, resp.message);
          this.$emit("flash");
          this.dialogVisible = false;
        } else {
          _this.$handleFailResp(_this, resp);
        }
      });
    },
  },
  mounted() {
    this.returnDepartment();
    this.returnacademicTitles();
  },
};
</script>

<style lang="less" scoped>
/deep/ .el-dialog {
  border-radius: 5px;
}

/deep/ .el-dialog__header {
  background-color: rgb(51, 55, 68);
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

/deep/ .el-dialog__title {
  font-size: 23px;
  color: white;
}

.el-input {
  width: 220px;
  margin-left: 40px;
  padding: 0;
}
.el-select {
  margin-left: 40px;
  width: 220px;
}

.el-main {
  align-items: center;
}

.el-main div:nth-child(n + 2) {
  margin-top: 10px;
}

.el-main div label {
  color: rgb(51, 55, 68);
  display: inline-block;
  width: 60px;
  font-size: 15px;
}

.el-button--primary {
  background-color: rgb(51, 55, 68);
  color: white;
  border: 0;
  width: 150px;
}
</style>
